Skip to content

fix(thold-functions): fix 13 logic bugs in RPN evaluation, SNMP traps, and notification handling#774

Open
somethingwithproof wants to merge 3 commits into
Cacti:developfrom
somethingwithproof:fix/thold-functions-logic-bugs
Open

fix(thold-functions): fix 13 logic bugs in RPN evaluation, SNMP traps, and notification handling#774
somethingwithproof wants to merge 3 commits into
Cacti:developfrom
somethingwithproof:fix/thold-functions-logic-bugs

Conversation

@somethingwithproof
Copy link
Copy Markdown

Summary

  • Bug 1 [CRITICAL]: $value = 'U' was an assignment, not comparison — caused wrong fallback to get_current_value() whenever $value was truthy
  • Bug 6 [CRITICAL]: RPN boolean operators pushed a result AND fell through to the switch, double-pushing onto the stack when operands were unknown/infinite
  • Bug 7 [HIGH]: 'ISNF' typo in $boolean array — ISINF operator was never recognized
  • Bug 2 [HIGH]: $thold_snmp_normal_traps and $thold_snmp_warning_traps used != 'on' (inverted) — normal and warning SNMP traps fired when the setting was off
  • Bug 14 [HIGH]: thold_fail_trigger read where thold_warning_fail_trigger was intended in SNMP description string
  • Bug 3/3b [HIGH]: case 'pes' (percent of events per site) was labeled case 'es' — duplicate of the raw-count case, permanently unreachable. $e['hosts'] corrected to $e['events']
  • Bug 4 [HIGH]: $emails['id'] (literal string key) used instead of $emails[$id] in attachment merge
  • Bug 13 [HIGH]: implode($device_ids) without separator produced invalid SQL IN clause; corrected to implode(', ', array_map('intval', $device_ids))
  • Bug 15 [HIGH]: strstr() !== 0 is always true (strstr never returns 0); corrected to !== false
  • Bug 12 [MEDIUM]: $thold_data['data_source_name'] > 0 compared a string numerically; corrected to strlen(...) > 0
  • Bug 11 [MEDIUM]: inner foreach ($data_sources as $data_source) shadowed the outer loop variable; renamed to $inner_data_source
  • Bug 15b [MEDIUM]: is_array($filename) && sizeof($filename) replaced with cacti_sizeof($filename) per project idiom
  • Bug extra [MEDIUM]: $data_source_name undefined in thold_expand_string elseif branch — corrected to $thold_data['data_source_name']

Added nosemgrep suppressions to 5 pre-existing eval()/exec() call sites with justification comments.

Test plan

  • Verify SNMP traps fire when config is on (not when off) for both warning and normal
  • Confirm RPN expressions with unknown/infinite operands return single result on stack
  • Confirm ISINF operator recognized in expression evaluations
  • Verify threshold suggested names use correct data source name key
  • Check pes (percent of events per site) trigger populates $triggers correctly

🤖 Generated with Claude Code

…raps, and notification

Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
Replace is_array+sizeof with cacti_sizeof per project idiom.
Add intval() to implode() on $device_ids SQL IN clause.

Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
…tring

$data_source_name was undefined in this branch; the correct source
is the $thold_data array key.

Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
Copilot AI review requested due to automatic review settings May 17, 2026 09:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant